<?php defined('SYSPATH') or die('No direct script access.');
/**
 * 帐号与登录
 *
 * @author  Yellow.Chow <aultoale@gmail.com>
 * @version $Id: account.php 41 2012-03-08 09:42:53Z yellow.chow $
 * @license http://www.gnu.org/licenses/gpl-3.0.html    GPL 3
 */
class Controller_Admin_Account extends Controller_Admin_Base
{

    /**
     * 会员登录
     */
    public function action_login()
    {
        if ($this->manager->is_logined() AND $this->request->method() !== HTTP_Request::POST)
        {
            $this->request->redirect(URL::site('admin'));
        }

        $errors = array();
        if ($this->request->is_post())
        {
            $post = Validation::factory($this->request->post())
                ->rule('account', 'not_empty')
                ->rule('password', 'not_empty')
                ->rule('captcha', 'not_empty')
                ->rule('captcha', 'Captcha::valid');
            if ($post->check()) // 验证通过
            {
                try
                {
                    $this->manager->login($post['account'], $post['password'], FALSE);
                    $this->request->redirect($this->session->get('redirect', URL::site('admin')));
                }
                catch (Kohana_Exception $e)
                {
                    $errors[] = $e->getMessage();
                }
            }
            $errors = array_merge($errors, $post->errors('admin.account'));
        }

        $this->view->errors = $errors;
    }

    /**
     * 退出登录
     */
    public function action_logout()
    {
        $this->manager->logout();
        $this->request->redirect(URL::site('admin/account/login'));
    }

    /**
     * 修改密码
     */
    public function action_password()
    {}

} // End Welcome
